<!--
 * @FilePath     : /layui/demo/16-6.html
 * @Description  : 拖拽上传
 * @Date         : 2025-02-25 13:55
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-02-25 13:57
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/layui/dist/css/layui.css" />
  </head>
  <body>
    <div class="layui-upload-drag" style="display: block" id="ID-upload-demo-drag">
      <i class="layui-icon layui-icon-upload"></i>
      <div>点击上传，或将文件拖拽到此处</div>
      <div class="layui-hide" id="ID-upload-demo-preview">
        <hr />
        <img src="" alt="上传成功后渲染" style="max-width: 100%" />
      </div>
    </div>

    <script src="/layui/dist/layui.js"></script>
    <script>
      layui.use(function () {
        var upload = layui.upload
        var $ = layui.$
        // 渲染
        upload.render({
          elem: '#ID-upload-demo-drag',
          url: '/layui/upload/up1', // 实际使用时改成您自己的上传接口即可。
          done: function (res) {
            layer.msg('上传成功')
            $('#ID-upload-demo-preview')
              .removeClass('layui-hide')
              .find('img')
              .attr('src', res.files.file)
            console.log(res)
          },
        })
      })
    </script>
  </body>
</html>
